//
//  JKRefreshView.swift
//  新浪微博
//
//  Created by Jack.Lin on 16/7/8.
//  Copyright © 2016年 Jack.Lin. All rights reserved.
//

import UIKit


/// 刷新视图 - 负责所有的视图变化
class JKRefreshView: UIView {

    // 刷新状态
    var refreshState: CZRefreshState = .Normal {
        didSet {
        
            switch refreshState {
            case .Normal:
                // 恢复状态
//                tipIcon.isHidden = false
//                indicator.stopAnimating()

                tipIcon?.isHidden = false
                indicator?.stopAnimating()
                
                tipLabel?.text = "继续使劲拉..."
                
                UIView.animate(withDuration: 0.25, animations: { 
                    self.tipIcon?.transform = CGAffineTransform.identity
                })
                
            case .Pulling:
                tipLabel?.text = "放手就刷新..."
                
                UIView.animate(withDuration: 0.25, animations: { 
                    self.tipIcon?.transform = CGAffineTransform(rotationAngle: CGFloat(M_PI + 0.001))
                })
                
            case .WillRefresh:
                tipLabel?.text = "正在刷新中..."
                
                tipIcon?.isHidden = true
                
                indicator?.startAnimating()
            }
        }
      
    }
    
    // 父视图的高度 - 为了刷新控件不需要关系当前具体的刷新视图是谁
    var parentViewHeight: CGFloat = 0
    
    
    // 提示图标
    @IBOutlet weak var tipIcon: UIImageView?
    // 提示标签
    @IBOutlet weak var tipLabel: UILabel?
    // 指示器
    @IBOutlet weak var indicator: UIActivityIndicatorView!

    class func refreshView() -> JKRefreshView  {
        
        let nib = UINib(nibName: "JKMeituanRefreshView", bundle: nil)
        
        return nib.instantiate(withOwner: nil, options: nil)[0] as! JKRefreshView
        
    }
    
}
